#!/bin/bash
# desc:python升级到3.10

python_ver=3.10.8

# 1.安装编译相关工具
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

# 2.下载安装包解压

cd /home
# wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
wget https://mirrors.huaweicloud.com/python/${python_ver}/Python-${python_ver}.tar.xz
tar -xvJf  Python-${python_ver}.tar.xz

# 3.编译安装

mkdir /usr/local/python3 #创建编译安装目录
cd Python-${python_ver}
./configure --prefix=/usr/local/python3
make && make install

# 4.创建软连接
#ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
#ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
ln -bs /usr/local/python3/bin/python3 /usr/bin/python3
ln -bs /usr/local/python3/bin/pip3 /usr/bin/pip3

#或者直接写入环境变量
#vim /etc/profile
#PATH=$PATH:/usr/local/python3/bin

# 5.验证是否成功
python3 -V
pip3 -V

if [ -f "/usr/local/python3/bin/supervisorctl" ];then
    ln -s /usr/local/python3/bin/supervisorctl /usr/bin/supervisorctl
    ln -s /usr/local/python3/bin/supervisord /usr/bin/supervisord
    ln -s /usr/local/python3/bin/echo_supervisord_conf /usr/bin/echo_supervisord_conf
fi